/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

import javax.ejb.EJB;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import service.SaleOrderDetailServiceLocal;

/**
 * Web application lifecycle listener.
 *
 * @author SONY
 */
@WebListener()
public class InitializeSaleOrderDetails implements ServletContextListener {
    
    @EJB SaleOrderDetailServiceLocal saleOrderDetailServiceLocal;

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        ServletContext context = sce.getServletContext();
        try {
            Context ctx = new InitialContext();
            saleOrderDetailServiceLocal = (SaleOrderDetailServiceLocal) ctx.lookup("java:comp/env/ejb/SaleOrderDetailServiceLocal");
            context.setAttribute("saleOrderDetailServiceLocal", saleOrderDetailServiceLocal);
        } catch (Exception ex) {
            System.err.println(ex);
        }
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
